package com.abc.example.enumeration;

import com.abc.example.exception.BaseException;
import com.abc.example.exception.ExceptionCodes;

/**
 * @className	: EDataType
 * @description	: 数据类型
 * @summary		:
 * @history		:
 * ------------------------------------------------------------------------------
 * date			version		modifier		remarks                   
 * ------------------------------------------------------------------------------
 * 2023/05/17	1.0.0		sheng.zheng		初版
 *
 */
public enum EDataType {
    dtCharE			(1,"Char"),
    dtByteE			(2,"Byte"),
    dtShortE		(3,"Short"),
    dtUnsignedShortE(4,"Unsigned Short"),
    dtIntE			(5,"Int"),
    dtUnsignedIntE	(6,"Unsigned Int"),
    dtLongE			(7,"Long"),
    dtUnsignedLongE	(8,"Unsigned Long"),
    dtFloatE		(9,"Float"),
    dtDoubleE		(10,"Double"),
    dtArrayE		(11,"Array"),
    dtStructE		(12,"Struct"),
    dtStringE		(13,"String"),
    dtBytearrayE	(14,"ByteArray"),
    dtBooleanE		(15,"Boolean"),
    dtEnumE			(16,"Enum"),
    dtCustomenumE	(17,"CustomEnum"),
    dtLocaldateE	(18,"LocalDate"),
    dtLocaltimeE	(19,"LocalTime"),
    dtLocaldatetimeE(20,"LocalDateTime"),
    dtDateE			(21,"Date"),
    dtMapE			(22,"Map"),
    dtUrlE			(23,"URL"),
	;	// 结束定义
	
	// 枚举值对应的code值
	int code;
	
	// 描述
	String desc;

	// 构造函数
	private EDataType(int code,String desc) {
	    this.code = code;
	    this.desc = desc;
	}

	// 属性code的getter方法
	public int getCode() {
	    return code;
	}

	// 属性code的setter方法
	public void setCode(int code) {
	    this.code = code;
	}
	
	// desc的getter/setter方法
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
	
	/**
	 * 
	 * @methodName	: getType
	 * @description	: 根据code获取枚举值
	 * @param code	: code值 
	 * @return		: code对应的枚举值
	 * @history		:
	 * ------------------------------------------------------------------------------
	 * date			version		modifier		remarks                   
	 * ------------------------------------------------------------------------------
	 * 2023/05/17	1.0.0		sheng.zheng		初版
	 *
	 */
	public static EDataType getType(int code) {
		// 返回值变量
		EDataType eRet = null;
		
		for (EDataType item : values()) {
			// 遍历每个枚举值
			if (code == item.getCode()) {
				// code匹配
				eRet = item;
				break;
			}
		}
		
		return eRet;
	}

	// 检查并获取指定code的枚举值
	public static EDataType getTypeByCode(int code) {
		EDataType item = getType(code);
		if (item == null) {
			throw new BaseException(ExceptionCodes.INVALID_ENUM_VALUE,"EDataType with code="+code);
		}
		
		return item;
	}	
}